package com.shujia.control;

import com.shujia.bean.Dept;
import com.shujia.service.CacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("cache")
public class CacheControl {

    @Autowired
    CacheService cacheService;

    /**
     * 需求：通过URL传入一个部门编号，之后将结果返回给调用方
     * @return
     */
    // 请求方式为：localhost:8080/cache/getDName/10
    @RequestMapping("getDName/{deptNo}")
    public String getDNameByDeptNo(@PathVariable int deptNo){
        System.out.println("control层中的getDNameByDeptNo被调用...");
        return cacheService.getDataByDeptNo(deptNo);
    }

    // 请求方式为：localhost:8080/cache/update 在PostMan中通过Post请求发送对象
    @RequestMapping("update")
    public String UpdateDept(@RequestBody Dept dept){
        cacheService.updateDept(dept);
        return dept.getdName()+ "更新成功";
    }

}
